package com.ttt.adbgui.jcomp;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.swing.*;
import java.awt.*;

@Component
public class JToast {

    @Autowired
    private JFrameComponent component;
    private JFrame jFrame;

    public void showDialog(String s) {

        jFrame = component.getDialogFrame();
        jFrame.setLocationRelativeTo(null);
        jFrame.setResizable(false);
        jFrame.setUndecorated(true);
        // jFrame.setLayout(null);
        Point location = component.getJFrame().getLocation();
        jFrame.setBounds((int) location.getX() + 480,(int)location.getY() + 280,180, 40);
        // jFrame.setBounds(1,1,180,40);
        jFrame.setBackground(Color.black);
        // jFrame.setOpacity(0.1f);

        JPanel panel = new JPanel();
        panel.setLayout(null);
        panel.setSize(180, 40);
        panel.setVisible(true);
        panel.setBorder(null);
        panel.setBackground(Color.BLACK);

        JTextField jLabel = new JTextField(s);
        jLabel.setBounds(0, 0, 180, 40);
        jLabel.setVisible(true);
        jLabel.setForeground(Color.white);
        jLabel.setHorizontalAlignment(SwingConstants.CENTER);
        jLabel.setOpaque(true);
        jLabel.setBorder(null);
        jLabel.setBackground(Color.BLACK);
        jLabel.setEditable(false);

        panel.add(jLabel);
        jFrame.add(panel);
        jFrame.setVisible(true);
    }

    public void dialogClose(){
        jFrame.dispose();
    }
}
